<?php
/**
 * Author: Hancock
 * Email: 84622365@qq.com
 * Date: 7/18/2016
 * Des: 系统管理员
 */
defined('INHkMvc') or exit('Access Invalid!');

class App_admin_sellerModel extends AppModel
{
   public function getGoodTkRateBySellerId($num_iid){
       $shop_rate=0;
       $seller_id=0; 
       if(M('app.good')->find(['num_iid'=>$num_iid])['seller_id']){
           $seller_id=M('app.good')->find(['num_iid'=>$num_iid])['seller_id'];
       }else{
           $seller_id=0; 
       }
       if($seller_id==0){
          $data=taobaoCurl('goodUpdate', ['num_iid' => $num_iid, 'perPageSize' =>40, 'shopTag' =>'-1']);
          if($data==302){
             return $shop_rate;
          }
          if(!empty($data['data']['pageList']) && isset($data['data']['pageList'])){
             if($this->find(['tb_seller_id'=>$seller_id])){
                 return $this->find(['tb_seller_id'=>$seller_id])['shop_rate'];
             }else{
                 return $shop_rate;  
             }
          }else{
          	return $shop_rate;
          }
       }else{
       	  if($this->find(['tb_seller_id'=>$seller_id])){
       	      return $this->find(['tb_seller_id'=>$seller_id])['shop_rate'];
       	  }else{
       	      return $shop_rate;  
       	  }
       }
   }
   public function getGoodRateTimeBySellerId($num_iid){
       $seller_id=0; 
       if(M('app.good')->find(['num_iid'=>$num_iid])['seller_id']){
           $seller_id=M('app.good')->find(['num_iid'=>$num_iid])['seller_id'];
       }else{
           $seller_id=0; 
       }
       if($seller_id==0){
          $data=taobaoCurl('goodUpdate', ['num_iid' => $num_iid, 'perPageSize' =>40, 'shopTag' =>'-1']);
          if($data==302){
             return time();
          }
          if(!empty($data['data']['pageList']) && isset($data['data']['pageList'])){
             if($this->find(['tb_seller_id'=>$seller_id])){
                 return $this->find(['tb_seller_id'=>$seller_id])['rate_time'];
             }else{
                 return time();  
             }
          }else{
            return time();
          }
       }else{
          if($this->find(['tb_seller_id'=>$seller_id])){
              return $this->find(['tb_seller_id'=>$seller_id])['rate_time'];
          }else{
              return time();  
          }
       }
   }
}

